<template>
  <div class="app-container">
    <div class="dashboard-editor-container">
      <el-row>
        <el-col :xs="24" :sm="24" :lg="24"
                style="padding-left:16px;padding-right: 16px;">
          <el-card class="cardbox1" :style="{background:$store.getters.theme}">
            <div class="cbox1">
              <p class="p1">权限中心简介</p>
              <p class="p2">为各个业务系统的权限的统一和集中管理,实现人员与角色的绑定，人员和角色对功能权限的授权管理，并将权限授权下发给业务系统。 功能包括角色管理、授权管理、集成API。支持多租户。</p>
            </div>
            <div class="cbox2">
              <el-image :src="require('@/framework/assets/welcomePicture.png')" fit="fill" />
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row>
        <el-col :xs="24" :sm="24" :lg="24"
                style="padding-left:16px;padding-right: 16px;margin-bottom: 16px;">
          <el-card style="margin-top:16px">
            <p class="title" style="margin:0 0 16px">数据统计分析</p>
            <PanelGroup @handleSetLineChartData="handleSetLineChartData" />
            <div style="margin-top: 16px; display: flex;justify-content: space-between;align-items: center;">
              <p class="title" style="margin:0 0 16px">业务用户授权情况</p>
              <div style="display: flex; justify-content: flex-end; ">
                <el-radio-group v-model="editableTabsValue" @change="getTime">
                  <el-radio-button
                    v-for="(item,index) in editableTabs"
                    :key="index"
                    :value="item.value"
                    :label="item.value"
                  >{{ item.label }}</el-radio-button>
                </el-radio-group>
                <el-date-picker
                  v-model="allDate"
                  style="margin-left: 12px;"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :picker-options="setDateRange"
                  @change="changeTime"
                />
              </div>
            </div>

            <auth-Situation-Bar-Chart ref="barChartRef" />
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>

</template>

<script>
import PanelGroup from './component/PanelGroup.vue'
import authSituationBarChart from './component/authSituationBarChart.vue'

export default {
  name: 'PermissionOverview',
  components: {
    PanelGroup,
    authSituationBarChart
  },
  data() {
    return {
      editableTabsValue: 7,
      editableTabs: [
        {
          label: '近七天',
          value: 7
        },
        {
          label: '近一个月',
          value: 30
        },
        {
          label: '近三个月',
          value: 90
        }
      ],
      tabIndex: 2,
      allDate: [],
      setDateRange: {
        disabledDate: (time) => {
          // 只能选择当前 1 年内的时间
          const year = 365 * 24 * 3600 * 1000
          // 注意：这是从当前日期开始往前算,往后的日期不可选
          return time.getTime() > Date.now() || time.getTime() < (Date.now()) - year
        }
      }
    }
  },
  computed: {

  },
  created() {
    this.$nextTick(() => {
      this.getTime(7)
    })
  },
  methods: {
    handleSetLineChartData(type) {
      // this.lineChartData = lineChartData[type]
    },
    changeTime(val) {
      if (!val) {
        this.allDate = []
        this.editableTabsValue = 7
        this.getTime(this.editableTabsValue)
      } else {
        this.editableTabsValue = null
        this.allDate = val
        this.beginTime = this.allDate[0]
        this.endTime = this.allDate[1]
        this.$refs.barChartRef.initChart(this.beginTime, this.endTime)
      }
    },
    getTime(n) {
      this.allDate = []
      const num = parseInt((n - 1) * 24 * 3600 * 1000)
      const days = new Date()
      const end = `${days.getFullYear()}-${days.getMonth() + 1}-${days.getDate()}`
      const dayend = new Date()
      dayend.setTime(dayend.getTime() - num)
      const start = `${dayend.getFullYear()}-${dayend.getMonth() + 1}-${dayend.getDate()}`
      this.changeDate = [start, end]
      if (this.changeDate) {
        this.beginTime = this.changeDate[0]
        this.endTime = this.changeDate[1]
      }
      this.$refs.barChartRef.initChart(this.beginTime, this.endTime)
    }

  }
}
</script>

  <style lang="scss" scoped>
   .cardbox1{
      margin-top: 16px;
      height: 200px;
        position: relative;
      .el-card__body{
        display: flex;
        // padding: 20px!important;
        .cbox1{
          width: 70%;
          margin-left: 20px;
          z-index: 2;
        }
        .cbox2{
          position: absolute;
        bottom: 20px;
        right: 20px;
        z-index: 1;
        margin-left: 20px;
        // img {
        //   width: 272px;
        //   height: 157px;
        // }
        }
        p{
          font-size: 18px;
          font-family: HarmonyOS Sans SC-Medium, HarmonyOS Sans SC;
          font-weight: 500;
          color: #FFFFFF;
          line-height: 24px;
        }
        .p2{
          font-size: 16px;
        // line-height: 32px;
        // font-weight: 300;
        // margin-top:16px;
        }
      }
    }
  </style>

